package cn.yanxiaohui.service.web.controller;

import javax.servlet.http.HttpServletRequest;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * controller的基类
 * @author yanxiaohui
 *
 */
public abstract class BaseController {
	
	Logger logger = LoggerFactory.getLogger(BaseController.class);
	
	public final static String ERROR = "common/error";
	
	/**
	 * 返回当前页数，参数用String是考虑到前端用户手动在地址栏随便输入的情况，方便转换
	 * 
	 **/
	protected Integer getPageNum(HttpServletRequest request, String paramName) {
		final String pageStr = request.getParameter(paramName);
		if (StringUtils.isEmpty(pageStr)) {
			return 1;
		}
		try {
			int pageNum = Integer.parseInt(pageStr);
			if (pageNum < 1) pageNum = 1;
			return pageNum;
		} catch (Exception ex) {
			return 1; // 默认是第一页
		}
	}
	
}
